package com.ktjy.config;

import com.ktjy.entity.SysRole;
import com.ktjy.entity.SysUser;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration //配置类 applicationContext.xml
@PropertySource(value = "classpath:user.properties",encoding = "utf-8") //<context:property-placeholder location="classpath:user.properties"/>
public class JavaConfig {
    @Value("${user.realname}")
    private String realName;
    @Value("${user.acount}")
    private String account;


    //<bean class="com.ktjy.entity.SysUser" id="sysUser"/>
    // <property name="role" ref="sysRole"/>
    // <property name="realName" value="张三"/>
    // <property name="account" value="zhangsan"/>
    // </bean>
    //对象类型的属性赋值用的是 方法参数注入
    @Bean
    public SysUser sysUser(SysRole sysRole){
        SysUser sysUser=new SysUser();
        sysUser.setRealName(realName);
        sysUser.setAccount(account);
        sysUser.setRole(sysRole);
        return sysUser;
    }
    //<bean class="com.ktjy.entity.SysRole" id="sysRole"/>
    // <property name="id" value="1"/>
    // <property name="roleName" value="管理员"/>
    // </bean>
    @Bean
    public SysRole sysRole(){
        SysRole sysRole=new SysRole();
        sysRole.setId(1l);
        sysRole.setRoleName("管理员");
        return sysRole;
    }
}
